﻿using System;
using Microsoft.SharePoint.Administration;
using System.Runtime.InteropServices;
using Microsoft.SharePoint.Utilities;
using System.ServiceModel;
using Microsoft.SharePoint.Administration.AccessControl;

namespace CodeCounsel.SharePoint.NavigationService
{
    [ServiceBehavior(
        InstanceContextMode = InstanceContextMode.PerSession,
        ConcurrencyMode = ConcurrencyMode.Multiple,
        IncludeExceptionDetailInFaults = true),
    Guid("f46c5a6a-0f73-4c1e-b11b-c2ffb70c19f9")]
    public class NavigationApplication
        : SPIisWebServiceApplication, INavigationApplication
    {
        protected override string InstallPath
        {
            get { return SPUtility.GetGenericSetupPath(@"WebServices\CodeCounsel.SharePoint.NavigationService"); }
        }

        protected override string VirtualPath
        {
            get { return "Navigation.svc"; }
        }

        protected override string DefaultEndpointName
        {
            get { return "http"; }
        }

        public override string TypeName
        {
            get { return "Navigation Application (Demo)"; }
        }

        public NavigationApplication()
        {
        }

        public NavigationApplication(string name, NavigationService service, 
            SPIisWebServiceApplicationPool applicationPool)
            : base(name, service, applicationPool)
        {
        }

        public static NavigationApplication Create(string name, 
            NavigationService service, SPIisWebServiceApplicationPool applicationPool)
        {
            NavigationApplication application = new NavigationApplication(name, service, applicationPool);
            application.Update();
            application.AddServiceEndpoint("http", SPIisWebServiceBindingType.Http);
            return application;
        }

        public string GetNavigationInformation()
        {
            return "Demo";
        }
    }
}
